//
//  HMSideslipViewController.m
//  cehuatext
//
//  Created by manman on 16/9/10.
//  Copyright © 2016年 manman. All rights reserved.
//

#import "HMSideslipViewController.h"
#import "HMSideslipHeadView.h"
#import "HMSideslipModel.h"
#import "HMSideslipCell.h"
#import "YYModel.h"
#import "NSObject+YYModel.h"
#import "KYTabbarController.h"
#import "HMHomeViewController.h"
#import "HMDocoterViewController.h"
#import "AboutUsViewController.h"
#import "HMManagerController.h"
#import "UMSocial.h"
static NSString *cellID = @"cellID";
@interface HMSideslipViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic)HMSideslipHeadView *hideV;
@property (strong, nonatomic)  KYTabbarController *contentVc;

@end
  
@implementation HMSideslipViewController
{
    NSArray *_modelList;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self loadData];
    [self setupContentVc];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupUI
{
   
    UITableView *tv = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tv.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sky"]];
    tv.opaque = NO;
//    tv.backgroundColor = [UIColor colorWithRed:124 / 255.0 green:125 / 255.0 blue:129 / 255.0 alpha:0.5];
    tv.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.7];
    [self.view addSubview:tv];
    HMSideslipHeadView *headerView = [[HMSideslipHeadView alloc]init];
    headerView.frame = CGRectMake(0, 0, tv.bounds.size.width, 100);
    headerView.userName.text = @"如来佛祖";
    headerView.userName.textColor = [UIColor whiteColor];
    headerView.userIcon.image = [UIImage imageNamed:@"avatar_patient_male_58C89562F58FD276F592420068DB8C09_0"];
    headerView.userPhone.text = @"121443434";
    tv.tableHeaderView = headerView;
    tv.scrollEnabled = NO;
    tv.dataSource = self;
    tv.delegate = self;
    [tv registerNib:[UINib nibWithNibName:@"HMSideslipCell" bundle:nil] forCellReuseIdentifier:cellID];
    tv.rowHeight = 60;

    
}

#pragma mark --- 数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    if(section == 0)
//    {
//        return 4;
//    }
    return 9;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HMSideslipCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];

    cell.model = _modelList[indexPath.row];
    return cell;


}
- (void)loadData
{
//解析pilst
    NSString *path = [[NSBundle mainBundle] pathForResource:@"sides.plist" ofType:nil];
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    _modelList = [NSArray yy_modelArrayWithClass:[HMSideslipModel class] json:arr];

}
#pragma mark - 2.添加容器视图控制器tabBarVc
- (void)setupContentVc {
    
    self.view.backgroundColor = [UIColor magentaColor];
    
    // 1.创建vc对象
     KYTabbarController *contentVc = [[KYTabbarController alloc] init];
    
    // 2.添加为子控制器
    [self addChildViewController:contentVc];
    
    // 3.设置容器视图的frame信息
    contentVc.view.frame = self.view.bounds;
    
    // 4.添加视图
    [self.view addSubview:contentVc.view];
    
    // 5.确定
    [contentVc didMoveToParentViewController:self];
    
    // 赋值!
    _contentVc = contentVc;
}
#pragma mark - 代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       // 2.创建控制器
    if(indexPath.row == 0)
    {
        
       HMHomeViewController *vc = [[HMHomeViewController alloc] init];

        [self.navigationController pushViewController:vc animated:YES];
        // 清除形变!
        [_contentVc tapAction:nil];
    }
    if(indexPath.row == 2)
    {
        
        HMManagerController *vc = [[HMManagerController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        
        // 3.跳转
        // - 获取自己所管理的子控制器 contentVc -> QQTabbarController!
        // - contentVc.selectedViewController -> UINavigationController!
        UINavigationController *nav = _contentVc.selectedViewController;
        
        [nav pushViewController:vc animated:NO];
        // 清除形变!
        [_contentVc tapAction:nil];
    }


    if(indexPath.row == 3)
    {
    
   HMDocoterViewController *vc = [[HMDocoterViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    
    // 3.跳转
    // - 获取自己所管理的子控制器 contentVc -> QQTabbarController!
    // - contentVc.selectedViewController -> UINavigationController!
    UINavigationController *nav = _contentVc.selectedViewController;
    
    [nav pushViewController:vc animated:NO];
        
        
    
    // 清除形变!
    [_contentVc tapAction:nil];
    }
    if(indexPath.row ==5)
    {
    
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Reader not supported by the current device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        
        [alert show];
    
    }
    
        if(indexPath.row == 7)
    {
            
            AboutUsViewController *vc = [[AboutUsViewController alloc] init];
            vc.hidesBottomBarWhenPushed = YES;
            
            // 3.跳转
            // - 获取自己所管理的子控制器 contentVc -> QQTabbarController!
            // - contentVc.selectedViewController -> UINavigationController!
            UINavigationController *nav = _contentVc.selectedViewController;
            
            [nav pushViewController:vc animated:NO];
            
            // 清除形变!
            [_contentVc tapAction:nil];
    }
    if (indexPath.row == 8) {
        [UMSocialSnsService presentSnsIconSheetView:self appKey:@"57d2dc57e0f55ab70c001420"
                                          shareText:@"XXX" shareImage:[UIImage imageNamed:@"Share_20.16690647482px_1183447_easyicon.net"]
                                    shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToWechatSession,
                                                     UMShareToWechatTimeline,
                                                     UMShareToQQ,UMShareToRenren,
                                                     UMShareToDouban,UMShareToSms,UMShareToFacebook,UMShareToTwitter,
                                                     
                                                     nil]
                                           delegate:nil];

    }
    


   
}






@end
